home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / Resources / Sound / AHI / Developer / examples / Low-level / 3rd party / GetAudioID / Source / GAI.S < prev   
Text File  |  1996-05-01  |  12KB  |  573 lines

  1. *************************************************
  2. *                        *
  3. *         (C) Copyright 1996        *
  4. *                        *
  5. *           Tomi Blinnikka        *
  6. *                        *
  7. *************************************************
  8. *                        *
  9. * DISTRIBUTION:                    *
  10. *                        *
  11. * The complete and unmodified archive, as     *
  12. * provided by Tomi Blinnikka, may be freely     *
  13. * redistributed via any means which preserves     *
  14. * its copyrights. The archive may not be sold     *
  15. * for profit.                    *
  16. *                        *
  17. * Permission granted to be distributed with the    *
  18. * AHI user/development software.        *
  19. *                        *
  20. *************************************************
  21. *                        *
  22. * DISCLAIMER:                    *
  23. *                        *
  24. * GETAUDIOID IS PROVIDED "AS-IS" AND SUBJECT TO *
  25. * CHANGE; NO WARRANTIES ARE MADE.  ALL USE IS    *
  26. * AT YOUR OWN RISK.  NO LIABILITY OR        *
  27. * RESPONSIBILITY IS ASSUMED.            *
  28. *                        *
  29. *************************************************
  30. *                        *
  31. * DESCRIPTION:                    *
  32. *                        *
  33. * A program to display AHI AudioID requester    *
  34. * and print selected ID in hex and decimal.    *
  35. *                        *
  36. * Requires Kickstart 2.04+, ahi.device 1+.    *
  37. *                        *
  38. *************************************************
  39. *                        *
  40. * HISTORY:                    *
  41. *                        *
  42. * Version 0.01    29.04.1996            *
  43. *     -0.99ö 29.04.1996            *
  44. *                        *
  45. * Basics.                    *
  46. *                        *
  47. *                        *
  48. * Version 1.00    30.04.1996            *
  49. *                        *
  50. * Works from CLI/Shell & Workbench.         *
  51. *                        *
  52. * Added TITLE, POSITIVE, NEGATIVE, LFORMAT &    *
  53. * PUBSCREEN options.                *
  54. *                        *
  55. * Added Locale support.                *
  56. *                        *
  57. *                        *
  58. * Version 1.01    01.05.1996            *
  59. *                        *
  60. * Doesn't set an initial AudioID anymore,    *
  61. * since Martin tells my shouldn't make        *
  62. * assumptions about direct IDs.            *
  63. *                        *
  64. * Recompiled with tags names from AHI beta 2.    *
  65. *                        *
  66. * If no mode was selected then returns -5.    *
  67. *                        *
  68. *                        *
  69. * BUGS:                        *
  70. *                        *
  71. *                        *
  72. *************************************************
  73.  
  74.     INCLUDE    "dos/dosextens.i"
  75.     INCLUDE    "devices/ahi.i"
  76.     INCLUDE "libraries/locale.i"
  77.     INCLUDE "workbench/startup.i"
  78.  
  79.     INCLUDE "JMPLibs.i"        ;Macros to open/close/call libs
  80.     INCLUDE    "lvo/ahi_lib.i"        ;ahi.device offsets
  81.  
  82. ;XREFs needed
  83.  
  84.     INCLUDE "XREF:2.0.xref"
  85.     INCLUDE "XREF:exec.xref"
  86.     INCLUDE "XREF:dos.xref"
  87.     INCLUDE "XREF:icon.xref"
  88.  
  89.  
  90. ;DEBUG_MODE    SET    1
  91.  
  92. AHI_DEFMIXFREQ:    EQU    30058        ;Sounds a lot better than 11kHz...
  93.  
  94. PROGVERSION:    macro
  95.         dc.b    "1.01 (01.05.96)"
  96.         endm
  97.  
  98.  
  99. ;Use these and leave a few hundred include lines out
  100.  
  101. TRUE:        EQU    1
  102. FALSE:        EQU    0
  103.  
  104. do_ToolTypes:    EQU    $36
  105.  
  106.  
  107.         Section GAI,CODE
  108.  
  109. START:        push    all            ;Save registers
  110.  
  111.         sub.l    a1,a1            ;Find our task
  112.         jlib    Exec,FindTask
  113.         move.l    d0,a4
  114.         move.l    pr_CLI(a4),d0
  115.         bne    OpenDos
  116.  
  117.         lea.l    pr_MsgPort(a4),a0
  118.         jlib    Exec,WaitPort
  119.         lea.l    pr_MsgPort(a4),a0
  120.         flib    Exec,GetMsg        ;Get WB message
  121.         move.l    d0,WBMsg
  122.  
  123. OpenDos:    openlib Dos,NoDos        ;Keep at beginning
  124.  
  125.         moveq.l    #0,d1            ;Go to root
  126.         jlib    Dos,CurrentDir
  127.         move.l    d0,OrigLock        ;This is where we came from
  128.  
  129.  
  130. ;Open locale.library
  131.  
  132.         openlib    Locale,NoLocale
  133.  
  134.         sub.l    a0,a0
  135.         jlib    Locale,OpenLocale
  136.         move.l    d0,Locale1
  137.  
  138.         sub.l    a0,a0            ;No locale, use default
  139.         lea.l    CatalogName1,a1
  140.         lea.l    CatalogTags,a2
  141.         jlib    Locale,OpenCatalogA    ;Open our catalog for this language
  142.         move.l    d0,GAICatalog
  143.         beq    NoLocale
  144.  
  145.  
  146. ;Here we set the text strings using locale support
  147.  
  148.         moveq.l    #0,d7
  149.         lea.l    CatStrings,a3        ;Def. String in A1
  150.  
  151. LocaleLoop:    move.l    d7,d0            ;StringNum in D0
  152.         move.l    GAICatalog,a0        ;Catalog in A0
  153.         move.l    (a3),a1            ;Default string in A1
  154.         jlib    Locale,GetCatalogStr
  155.  
  156.         move.l    d0,(a3)
  157.  
  158.         add.l    #1,d7
  159.         add.l    #4,a3
  160.         cmp.l    #CatStrAmount,d7
  161.         bne    LocaleLoop
  162.  
  163.  
  164. ;Fix strings that aren't move.l'd
  165.  
  166. NoLocale:    move.l    STRAHIReqTitle1,OptTitle
  167.         move.l    STRPositiveText2,OptPositive
  168.         move.l    STRNegativeText2,OptNegative
  169.  
  170.  
  171.         tst.l    WBMsg
  172.         beq    CLIStart        ;Skip WB stuff if from CLI
  173.  
  174.  
  175. ;Open CON: window where we print errors and the result.
  176.  
  177.         move.l    #CONName,d1
  178.         move.l    #MODE_OLDFILE,d2
  179.         jlib    Dos,Open
  180.         move.l    d0,CONFile
  181.         beq    ShutDown
  182.         move.l    CONFile,_stdout
  183.  
  184.         openlib Icon,NoIcon
  185.  
  186.         move.l    WBMsg,a0
  187.         move.l    sm_ArgList(a0),a1
  188.         move.l    wa_Lock(a1),d1
  189.         jlib    Dos,CurrentDir        ;Change to the directory where our icon is
  190.  
  191.  
  192. ;The icon we open here can't be free'd until all the data from them has
  193. ;been dealt with, i.e. until the progrma ends.
  194.  
  195.         move.l    WBMsg,a0
  196.         move.l    sm_ArgList(a0),a1
  197.         move.l    wa_Name(a1),a0
  198.         jlib    Icon,GetDiskObject    ;Get icon
  199.         move.l    d0,DiskObject
  200.         beq    MainStart
  201.  
  202. DoToolType1:    move.l    d0,a4
  203.         move.l    do_ToolTypes(a4),a0
  204.         lea.l    DECIMALText1,a1
  205.         flib    Icon,FindToolType
  206.         tst.l    d0
  207.         beq    DoToolType2
  208.         move.l    #1,OptDecimal        ;This user wants decimal ID
  209.  
  210. DoToolType2:    move.l    do_ToolTypes(a4),a0
  211.         lea.l    TITLEText1,a1
  212.         flib    Icon,FindToolType
  213.         tst.l    d0
  214.         beq    DoToolType3
  215.         move.l    d0,OptTitle        ;This title, please
  216.  
  217. DoToolType3:    move.l    do_ToolTypes(a4),a0
  218.         lea.l    POSITIVEText1,a1
  219.         flib    Icon,FindToolType
  220.         tst.l    d0
  221.         beq    DoToolType4
  222.         move.l    d0,OptPositive        ;This positive gad text
  223.  
  224. DoToolType4:    move.l    do_ToolTypes(a4),a0
  225.         lea.l    NEGATIVEText1,a1
  226.         flib    Icon,FindToolType
  227.         tst.l    d0
  228.         beq    DoToolType5
  229.         move.l    d0,OptNegative        ;This negative gad text
  230.  
  231. DoToolType5:    move.l    do_ToolTypes(a4),a0
  232.         lea.l    LFORMATText1,a1
  233.         flib    Icon,FindToolType
  234.         tst.l    d0
  235.         beq    DoToolType6
  236.         move.l    d0,OptLFormat        ;Format with this
  237.  
  238. DoToolType6:    move.l    do_ToolTypes(a4),a0
  239.         lea.l    PUBSCREENText1,a1
  240.         flib    Icon,FindToolType
  241.         tst.l    d0
  242.         beq    DoToolType7
  243.         move.l    d0,OptPubScreen        ;Open on this public screen
  244. DoToolType7:
  245.         bra    MainStart        ;Skip CLI stuff
  246.  
  247.  
  248. CLIStart:    jlib    Dos,Output
  249.         move.l    d0,_stdout
  250.  
  251.         move.l    #CLTemplate1,d1
  252.         move.l    #CLArray1,d2
  253.         moveq.l    #0,d3
  254.         flib    Dos,ReadArgs        ;Read options from CLI
  255.         move.l    d0,RDArgs1
  256.         beq    NoRDArgs
  257.  
  258.  
  259. ;Open ahi.device
  260.  
  261. MainStart:    OPENAHI    1
  262.         move.l    d0,_AHIBase
  263.         beq    NoAHI            ;Open failed
  264.  
  265.  
  266. ;Let's set all the options correctly
  267.  
  268.         move.l    (OptTitle),ReqTitle
  269.         move.l    (OptPositive),ReqPos
  270.         move.l    (OptNegative),ReqNeg
  271.         move.l    (OptPubScreen),ReqPubScr
  272.  
  273.  
  274. ;Here we go and check that the user specified formatting string doesn't
  275. ;contain more than two '%ld' strings.
  276.  
  277.         move.l    OptLFormat,d2
  278.         beq    OpenAHIReq        ;Check if available
  279.  
  280.         bsr    CheckLegality        ;Check if valid
  281.         tst.l    d2
  282.         beq    BadFmt            ;ERROR: Invalid
  283.  
  284.  
  285. ;Allocate AHI's audio requester
  286.  
  287. OpenAHIReq:    lea.l    AHIReqTags1,a0
  288.         jlib    AHI,AHI_AllocAudioRequestA
  289.         move.l    d0,AHIReq1
  290.         beq    NoAHIReq        ;Allocation failed
  291.  
  292.  
  293. ;Show requester
  294.  
  295.         move.l    d0,a0
  296.         lea.l    AHIReqTags2,a1
  297.         flib    AHI,AHI_AudioRequestA
  298.         cmp.l    #TRUE,d0
  299.         bne    CheckCancel        ;Positive gad _not_ pressed
  300.  
  301. ;Get values from requester and set then into the formatting template
  302.  
  303.         move.l    AHIReq1,a0
  304.  
  305.         cmp.l    #AHI_INVALID_ID,ahiam_AudioID(a0)
  306.         beq    CheckCancel        ;None selected
  307.  
  308.         lea.l    VFPrintfArgv,a1
  309.         move.l    ahiam_AudioID(a0),0(a1)
  310.         move.l    ahiam_MixFreq(a0),4(a1)
  311.  
  312.         move.l    #FmtString1,d2        ;Default formatting string
  313.  
  314.         tst.l    OptDecimal        ;Test for user's FmtString
  315.         beq    CLIOpts2
  316.         move.l    #FmtString2,d2        ;Print audio ID in decimal
  317.  
  318. CLIOpts2:    tst.l    OptLFormat
  319.         beq    PrintResult
  320.         move.l    OptLFormat,d2        ;Print audio ID in hex
  321.  
  322. PrintResult:    move.l    _stdout,d1
  323.         move.l    a1,d3
  324.         jlib    Dos,VFPrintf        ;Print chosen mode
  325.  
  326.         tst.l    OptLFormat
  327.         beq    ShutDown
  328.         lea.l    CRLFText1,a0
  329.         bsr    Printer            ;The user string needs a CRLF pair
  330.  
  331.         bra    ShutDown
  332.  
  333.  
  334. ;ShutDown routine. This cleans up EVERYTHING.
  335. ;
  336. ;We have three ways to start it:
  337. ;
  338. ;1. ERRShutDown        - does a quick turn in Printer to print anything in a0 first
  339. ;2. ERRShutDown2    - makes sure we return an error code when finished
  340. ;3. ShutDown        - a normal or non-fatal shutdown
  341.  
  342.  
  343. ERRShutDown:    bsr    Printer
  344. ERRShutDown2:    move.l    #RETURN_FAIL,RetCode
  345.  
  346. ShutDown:    tst.l    _AHIBase
  347.         beq    ShutDown7000
  348.         move.l    AHIReq1,a0            ;Allowed to be NULL
  349.         jlib    AHI,AHI_FreeAudioRequest
  350.  
  351. ShutDown7000:    tst.l    CONFile
  352.         beq    ShutDown6000
  353.         move.l    CONFile,d1
  354.         jlib    Dos,Close
  355.  
  356. ShutDown6000:    move.l    RDArgs1,d1
  357.         beq    ShutDown5000
  358.         jlib    Dos,FreeArgs
  359.  
  360. ShutDown5000:    tst.l    _DosBase
  361.         beq    ShutDown4000
  362.         move.l    OrigLock,d1            ;Can be zero for root
  363.         jlib    Dos,CurrentDir
  364.  
  365. ShutDown4000:    tst.l    DiskObject
  366.         beq    ShutDown1500
  367.         move.l    DiskObject,a0
  368.         jlib    Icon,FreeDiskObject
  369.  
  370. ShutDown1500:    tst.l    _LocaleBase
  371.         beq    ShutDown1000
  372.         move.l    GAICatalog,a0
  373.         jlib    Locale,CloseCatalog
  374.  
  375. ShutDown1000:    CLOSEAHI
  376.         closlib    Locale
  377.         closlib    Icon
  378.         closlib    Dos
  379.  
  380.         move.l    WBMsg,d2
  381.         beq    ShutDown100
  382.         jlib    Exec,Forbid
  383.         move.l    d2,a1
  384.         flib    Exec,ReplyMsg
  385.  
  386. ShutDown100:    pull    all
  387.         move.l    RetCode,d0
  388.         rts
  389.  
  390.  
  391. ;Subroutines
  392.  
  393.  
  394. ;CheckLegality does a simple check on the user provided formatting string
  395. ;so that we hopefully can't cause any Enforcer hits or any other nasty
  396. ;things
  397. ;
  398. ;INPUTS    D2 = Pointer to formatting string
  399. ;
  400. ;OUTPUT    D2 = NULL for error or original string
  401.  
  402. CheckLegality:    move.l    d2,a0
  403.         clr.b    d1            ;'%' counter
  404.  
  405. CheckLegality2:    tst.b    (a0)
  406.         beq    CheckLeg_OUT        ;Do until NULL
  407.         cmp.b    #'%',(a0)+
  408.         bne    CheckLegality2
  409.         cmp.b    #'%',(a0)        ;Let user print %-sign
  410.         bne    CheckLegality3
  411.         add.l    #1,a0
  412.         bra    CheckLegality2
  413. CheckLegality3:    add.b    #1,d1
  414.         cmp.b    #3,d1
  415.         bne    CheckLegality2        ;OK if 2 or under
  416. CheckLegality4:    clr.l    d2            ;Illegal
  417. CheckLeg_OUT:    rts
  418.  
  419.  
  420. ;Error handling routines
  421.  
  422. NoDos:        pull    all
  423.         move.l    #RETURN_FAIL,d0
  424.         rts
  425.  
  426. CheckCancel:    move.l    #RETURN_WARN,RetCode    ;Set return code to WARN
  427. NoRDArgs:    jlib    Dos,IoErr
  428.         move.l    d0,d1
  429.         beq    ShutDown        ;User cancelled
  430.         moveq.l    #0,d2
  431.         flib    Dos,PrintFault
  432.         bra    ERRShutDown2
  433.  
  434. NoAHI:        move.l    STRNoAHIText1,a0
  435.         bra    ERRShutDown
  436.  
  437. NoIcon:        move.l    STRNoIconText1,a0
  438.         bra    ERRShutDown
  439.  
  440. NoAHIReq:    move.l    STRNoAHIReqText1,a0
  441.         bra    ERRShutDown
  442.  
  443. BadFmt:        move.l    STRBadFormatText1,a0
  444.         bra    ERRShutDown
  445.  
  446.  
  447. ;Normal print function with Enforcer hit checks
  448.  
  449. Printer:    cmp.l    #0,a0
  450.         beq    Printer_OUT        ;No string
  451.         tst.b    (a0)
  452.         beq    Printer_OUT        ;No content
  453.         move.l    _stdout,d1
  454.         move.l    a0,d2
  455.         jlib    Dos,FPuts        ;Print buffered
  456. Printer_OUT:    rts
  457.  
  458.  
  459. ;Reservations start here
  460.  
  461.         libnames            ;This contains macros for the library names
  462.  
  463.         ds.l    0
  464.  
  465.  
  466. ;CLI/Shell stuff
  467.  
  468. RDArgs1:    dc.l    0            ;CLI arguments
  469. RetCode:    dc.l    RETURN_OK        ;Return this on exit
  470.  
  471.  
  472. ;Options
  473.  
  474. CLArray1:
  475. OptDecimal:    dc.l    0            ;Print ID in decimal
  476. OptTitle:    dc.l    0            ;Window title
  477. OptPositive:    dc.l    0            ;Positive gad text 'OK'
  478. OptNegative:    dc.l    0            ;Negative gad text 'Cancel'
  479. OptLFormat:    dc.l    0            ;User defined formatting
  480. OptPubScreen:    dc.l    NULLText1        ;Screen to open on
  481.  
  482.  
  483. ;File stuff
  484.  
  485. CONFile:    dc.l    0            ;Actuall a CON window
  486. _stdout:    dc.l    0            ;CLI or 'CON:'
  487. OrigLock:    dc.l    0            ;Directory where we started
  488.  
  489.  
  490. ;Workbench stuff
  491.  
  492. WBMsg:        dc.l    0            ;WB message
  493. DiskObject:    dc.l    0            ;Icon
  494.  
  495.  
  496. ;AHI stuff
  497.  
  498. _AHIBase:    dc.l    0            ;AHI device base
  499. AHIReq1:    dc.l    0            ;AudioID requester
  500.  
  501. VFPrintfArgv:    dc.l    0,0            ;AHIAudioID, AHIMixFreq
  502.  
  503.  
  504. ;Locale stuff
  505.  
  506. GAICatalog:    dc.l    0            ;Our translation file
  507. Locale1:    dc.l    0            ;Locale we're using
  508.  
  509.  
  510. ;Text strings
  511.  
  512. CLTemplate1:    dc.b    "DEC=DECIMAL/S,TITLE/K,POSITIVE/K,NEGATIVE/K,"
  513.         dc.b    "LFORMAT/K,PUBSCREEN/K",0
  514. DECIMALText1:    dc.b    "DECIMAL",0
  515. TITLEText1:    dc.b    "TITLE",0
  516. POSITIVEText1:    dc.b    "POSITIVE",0
  517. NEGATIVEText1:    dc.b    "NEGATIVE",0
  518. LFORMATText1:    dc.b    "LFORMAT",0
  519. PUBSCREENText1:    dc.b    "PUBSCREEN",0
  520. CONName:    dc.b    "CON:0/10/500/70/GetAudioID/CLOSE/AUTO/WAIT",0
  521. Version:    dc.b    "$VER: GetAudioID "
  522.         PROGVERSION
  523.         dc.b    " (c) Copyright Tomi Blinnikka 1996",0
  524. FmtString1:    dc.b    "AUDIOID=0x%08lx MIXFREQ=%ld\r\n",0
  525. FmtString2:    dc.b    "AUDIOID=%ld MIXFREQ=%ld\r\n",0
  526. CRLFText1:    dc.b    "\r\n"        ;Continues on next line!
  527. NULLText1:    dc.b    "",0
  528.  
  529.  
  530. ;Locale strings
  531.  
  532. EnglishText1:    dc.b    "english",0
  533. CatalogName1:    dc.b    "GetAudioID.catalog",0
  534.  
  535.  
  536. ;Taglists
  537.  
  538.         ds.l    0        ;Long align
  539.  
  540. ;Tags for requester allocation
  541.  
  542. AHIReqTags1:    dc.l    AHIR_PubScreenName
  543. ReqPubScr:    dc.l    0
  544.         dc.l    TAG_DONE
  545.  
  546.  
  547. ;Tags for showing requester
  548.  
  549. AHIReqTags2:    dc.l    AHIR_TitleText
  550. ReqTitle:    dc.l    0
  551.         dc.l    AHIR_PositiveText
  552. ReqPos:        dc.l    0
  553.         dc.l    AHIR_NegativeText
  554. ReqNeg:        dc.l    0
  555.         dc.l    AHIR_DoMixFreq,TRUE            ;Have slider for MixFrequency
  556.         dc.l    AHIR_InitialMixFreq,AHI_DEFMIXFREQ    ;Start with this MixFreq
  557.         dc.l    TAG_DONE
  558.  
  559.  
  560. ;Locale tags
  561.  
  562. CatalogTags:    dc.l    OC_Language,0
  563.         dc.l    OC_BuiltInLanguage,EnglishText1    ;We have this language built-in
  564.         dc.l    TAG_DONE
  565.  
  566.  
  567. ;Locale text strings
  568.  
  569.         INCDIR    "LWF:AHI/GetAudioID/"        ;Change to your path
  570.         INCLUDE    "GAI_locale.i"
  571.  
  572.         END
  573.